Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/takserver/src/commonMain/kotlin/org/meshtastic/core/takserver/CoTXmlFrameBuffer.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.19 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tf0883e@fileTb4b4b4:Te6edf3SuppressTb4b4b4(Ta5d6ff"Ta5d6ffLoopWithTooManyJumpStatementsTa5d6ff"Tb4b4b4)

Tff7b72package T7ee787org.meshtastic.core.takserver

Tff7b72import T7ee787okio.Buffer
Tff7b72import T7ee787okio.ByteString.Companion.encodeUtf8

Tff7b72internal Tff7b72class T56d364CoTXmlFrameBufferTb4b4b4(Tff7b72private Tff7b72val Te6edf3maxMessageSizeTb4b4b4: Tffa657Long Tff7b72= Te6edf3DEFAULT_MAX_TAK_MESSAGE_SIZETb4b4b4) Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3buffer Tff7b72= Te6edf3BufferTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72var Te6edf3discardingUntilNextEvent Tff7b72= Tff7b72false

Tff7b72fun Td2a8ffappendTb4b4b4(Te6edf3dataTb4b4b4: Te6edf3ByteArrayTb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Tffa657StringTff7b72> Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3writeTb4b4b4(Te6edf3dataTb4b4b4)

Tff7b72if Tb4b4b4(Te6edf3discardingUntilNextEventTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3nextEventIdx Tff7b72= Te6edf3bufferTb4b4b4.Te6edf3indexOfTb4b4b4(Te6edf3EVENT_START_BYTESTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3nextEventIdx Tff7b72=Tff7b72= Tff7b72-T79c0ff1LTb4b4b4) Tb4b4b4{
T8b949e// Keep the last few bytes in case the start tag is split across chunks
Tff7b72if Tb4b4b4(Te6edf3bufferTb4b4b4.Te6edf3size Tff7b72> Te6edf3EVENT_START_BYTESTb4b4b4.Te6edf3sizeTb4b4b4) Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3skipTb4b4b4(Te6edf3bufferTb4b4b4.Te6edf3size Tff7b72- Te6edf3EVENT_START_BYTESTb4b4b4.Te6edf3sizeTb4b4b4.Te6edf3toLongTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Tff7b72return Te6edf3emptyListTb4b4b4(Tb4b4b4)
Tb4b4b4}
Te6edf3discardingUntilNextEvent Tff7b72= Tff7b72false
Te6edf3bufferTb4b4b4.Te6edf3skipTb4b4b4(Te6edf3nextEventIdxTb4b4b4)
Tb4b4b4}

Tff7b72val Te6edf3messages Tff7b72= Te6edf3mutableListOfTff7b72<Tffa657StringTff7b72>Tb4b4b4(Tb4b4b4)

Tff7b72while Tb4b4b4(Tff7b72trueTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3startIdx Tff7b72= Te6edf3bufferTb4b4b4.Te6edf3indexOfTb4b4b4(Te6edf3EVENT_START_BYTESTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3startIdx Tff7b72=Tff7b72= Tff7b72-T79c0ff1LTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3bufferTb4b4b4.Te6edf3size Tff7b72> Te6edf3maxMessageSizeTb4b4b4) Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3clearTb4b4b4(Tb4b4b4)
Te6edf3discardingUntilNextEvent Tff7b72= Tff7b72true
Tb4b4b4}
Tff7b72break
Tb4b4b4}

Tff7b72if Tb4b4b4(Te6edf3startIdx Tff7b72> T79c0ff0LTb4b4b4) Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3skipTb4b4b4(Te6edf3startIdxTb4b4b4)
Tb4b4b4}

Tff7b72val Te6edf3endIdx Tff7b72= Te6edf3bufferTb4b4b4.Te6edf3indexOfTb4b4b4(Te6edf3EVENT_END_BYTESTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3endIdx Tff7b72=Tff7b72= Tff7b72-T79c0ff1LTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3bufferTb4b4b4.Te6edf3size Tff7b72> Te6edf3maxMessageSizeTb4b4b4) Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3clearTb4b4b4(Tb4b4b4)
Te6edf3discardingUntilNextEvent Tff7b72= Tff7b72true
Tb4b4b4}
Tff7b72break
Tb4b4b4}

Tff7b72val Te6edf3xmlEnd Tff7b72= Te6edf3endIdx Tff7b72+ Te6edf3EVENT_END_BYTESTb4b4b4.Te6edf3size
Tff7b72if Tb4b4b4(Te6edf3xmlEnd Tff7b72<Tff7b72= Te6edf3maxMessageSizeTb4b4b4) Tb4b4b4{
Te6edf3messages Tff7b72+Tff7b72= Te6edf3bufferTb4b4b4.Te6edf3readUtf8Tb4b4b4(Te6edf3xmlEndTb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3skipTb4b4b4(Te6edf3xmlEndTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tff7b72return Te6edf3messages
Tb4b4b4}

Tff7b72fun Td2a8ffclearTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3bufferTb4b4b4.Te6edf3clearTb4b4b4(Tb4b4b4)
Te6edf3discardingUntilNextEvent Tff7b72= Tff7b72false
Tb4b4b4}

Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3EVENT_START_BYTES Tff7b72= Ta5d6ff"Ta5d6ff<eventTa5d6ff"Tb4b4b4.Te6edf3encodeUtf8Tb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3EVENT_END_BYTES Tff7b72= Ta5d6ff"Ta5d6ff</event>Ta5d6ff"Tb4b4b4.Te6edf3encodeUtf8Tb4b4b4(Tb4b4b4)

T8b949e// 256KB is still 25× larger than any realistic CoT event (~10KB max). Using 8MB
T8b949e// would allow a TAK client with the shared cert to exhaust memory on mobile
T8b949e// devices by opening N connections × 8MB per frame buffer.
Tff7b72private Tff7b72const Tff7b72val Te6edf3DEFAULT_MAX_TAK_MESSAGE_SIZE Tff7b72= T79c0ff2T79c0ff5T79c0ff6L Tff7b72* T79c0ff1T79c0ff0T79c0ff2T79c0ff4
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.09s